<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
	$(document).ready(function(){
		$("#listBtn").click(function(){
			location.href="qagetListBoard.do";
		});
		$("#adjustBtn").click(function(){
			//alert("11111111");
			 if(confirm("수정하시겠습니까?")){
			location.href="${initParam.root}/updatePage.do?no=${requestScope.map.bvo.no}";
			} else
				return false;
		});
		$("#deleteBtn").click(function(){
			if(confirm("삭제하시겠습니까?")){
				location.href="${initParam.root}/qadeleteBoard.do?no=${requestScope.map.bvo.no}&id=${sessionScope.mvo.id}";
			}else{
				return false;
			}
		});
		
		// 댓글 쓰기
		$("#insertRe").click(function(){
			//alert("dfs");
			location.href="${initParam.root}/insertReply.do?boardVO.no=${requestScope.map.bvo.no}"+
					"&memberVO.id=${sessionScope.mvo.id}&rcontent="+$("#replyContent").val();
		});
		
		// 댓글 삭제
		$(":input[name=redel]").click(function() {
			//alert($(this).next().val());
			 if(confirm("삭제 하시겠습니까?")) {
				location.href="${initParam.root}/deleteReply.do?rno="+$(this).next().val()+"&refno=${requestScope.map.bvo.no}"+"&id=${sessionScope.mvo.id}";
			} else {
				return false;
			}
		});
		
		// 댓글 수정
		$(":input[name=reup]").click(function() {
				//alert($(this).next().val());
				//alert($(this).next().next().val());
			var no = $(this).next().val();
			$("#editReplyDialog").html("<input type=text id=updateReplyContent value="+$(this).next().next().val()+">").dialog({
				resizable:false,
				height:200,
				modal:true,
				buttons: {
					'수정':function() {
						//alert(no);
						//alert($("#updateReplyContent").val());
						location.href="${initParam.root}/updateReply.do?rno="+no+"&boardVO.no="+$("#bno").val()+"&rcontent="+$("#updateReplyContent").val();
					},
					'취소':function() {
						$(this).dialog('close');
					}//function
				}//button
			});//dialog
		});//click
		
		$(":input[name=restep]").click(function() {
			//alert($(this).next().val());
			var ref=$(this).next().val();
			$("#reReplyDialog").html("<input type=text id=reReplyContent>").dialog({
				resizable:false,
				height:200,
				modal:true,
				buttons: {
					'덧글':function() {
						//alert(no);
						//alert($("#updateReplyContent").val());
						location.href="${initParam.root}/reReply.do?ref="+ref+"&boardVO.no="+$("#bno").val()+"&rcontent=→"+$("#reReplyContent").val()+"&memberVO.id=${sessionScope.mvo.id}";
					},
					'취소':function() {
						$(this).dialog('close');
					}//function
				}//button
			});//dialog 
		});
		
		// 댓글 채택
		$(":input[name=adopt]").click(function(){
			//alert($(this).next().val());
			if(confirm("채택하시겠습니까??")){
				location.href="${initParam.root}/checkAdopt.do?no=${requestScope.map.bvo.no}&id=${sessionScope.mvo.id}&rno="+$(this).next().val();
			}//if
		});//click
	});//function
</script>
</head>
<body>
<center>
<c:if test="${sessionScope.mvo!=null }">
<table rules="all">
	<tr>
		<td>글번호 :${requestScope.map.bvo.no }</td><td>제목 :${requestScope.map.bvo.title } </td><td>아이디 :${requestScope.map.bvo.memberVO.id }</td>
	</tr>
	<tr>
		<td colspan="1">조회수 :${requestScope.map.bvo.count }<td colspan="2">날짜 :${requestScope.map.bvo.writedate }</td>
	</tr>
	<tr>
	<td colspan="3"><textarea rows="10" cols="45" name="content" readonly="readonly">${requestScope.map.bvo.content }</textarea></td>
	</tr>
</table>
</c:if>
<c:if test="${sessionScope.mvo!=null }">
<input type="button" id="listBtn" value="목록">
<c:if test="${sessionScope.mvo.id==requestScope.map.bvo.memberVO.id}">
<input type="button" id="adjustBtn" value="수정">
<input type="button" id="deleteBtn" value="삭제">
</c:if>
</c:if>
<br><br>
<!-- 현재 보이는 게시글 번호 -->
<input type="hidden" value="${requestScope.map.bvo.no }" id="bno">

<!-- 댓글 테이블 -->
<!-- 채택되지 않은 테이블 -->
	<c:if test="${requestScope.map.bvo.adopt==0 }">
		<c:if test="${sessionScope.mvo!=null }">
			<table>
			<c:forEach items="${requestScope.map.list }" var="list">
				<tr>
					<td>${list.memberVO.id}</td>
					<td>${list.rcontent }</td>
					<td>${list.rwritedate }</td>
					<c:choose>
						<c:when test="${list.restep == 0 }">
							<td width="200" colspan="3"><input type="button" name="restep" value="답글">
							<input type="hidden" name="ref" value="${list.rno }">
								<c:if test="${sessionScope.mvo.id==list.memberVO.id }">
												<input type="hidden" name="rno" value="${list.rno }">
												<input type="button" name="reup" value="수정">
												<input type="hidden" name="rno" value="${list.rno }">
												<input type="hidden" name="rcontent" value="${list.rcontent }">
												<input type="button" name="redel" value="삭제">
												<input type="hidden" name="rno" value="${list.rno }">
								</c:if>
						<c:if test="${sessionScope.mvo.id==requestScope.map.bvo.memberVO.id&&requestScope.map.bvo.adopt==0&&list.memberVO.id!=sessionScope.mvo.id}">
							<input type="button" name="adopt" value="채택">
							<input type="hidden" name="rno" value="${list.rno }">
						</c:if>
							</td>
						</c:when>
						<c:otherwise>
								<c:if test="${sessionScope.mvo.id==list.memberVO.id }">
											<td width="200" colspan="3">		
												<input type="hidden" name="rno" value="${list.rno }">
												<input type="button" name="reup" value="수정">
												<input type="hidden" name="rno" value="${list.rno }">
												<input type="hidden" name="rcontent" value="${list.rcontent }">
												<input type="button" name="redel" value="삭제">
												<input type="hidden" name="rno" value="${list.rno }">
											</td>
								</c:if>
						</c:otherwise>
					</c:choose>
				</tr>
				</c:forEach>
				<tr>
					<td>${sessionScope.mvo.id }</td>
					<td colspan="4"><textarea  rows="2" cols="50" id="replyContent" style="resize:none"></textarea></td>
					<td><input type="button" id="insertRe" value="댓글"></td>
				</tr>
			</table>
		</c:if>
	</c:if>

<!-- 채택된 댓글 테이블 -->
<c:if test="${requestScope.map.bvo.adopt==1 }">
	<c:if test="${sessionScope.mvo!=null }">
			<table>
			<c:forEach items="${requestScope.map.list }" var="list">
				<tr>
					<td>${list.memberVO.id}</td>
					<td>${list.rcontent }</td>
					<td>${list.rwritedate }</td>
					<c:choose>
						<c:when test="${list.restep == 0 }">
							<td width="200" colspan="3"><input type="button" name="restep" value="답글">
							<input type="hidden" name="ref" value="${list.rno }">
								<c:if test="${sessionScope.mvo.id==list.memberVO.id }">
												<input type="hidden" name="rno" value="${list.rno }">
												<input type="button" name="reup" value="수정">
												<input type="hidden" name="rno" value="${list.rno }">
												<input type="hidden" name="rcontent" value="${list.rcontent }">
												<input type="button" name="redel" value="삭제">
												<input type="hidden" name="rno" value="${list.rno }">
								</c:if>
							<c:if test="${list.radopt==1 }">
								채택됨
							</c:if>
							</td>
						</c:when>
						<c:otherwise>
								<c:if test="${sessionScope.mvo.id==list.memberVO.id }">
											<td width="200" colspan="3">		
												<input type="hidden" name="rno" value="${list.rno }">
												<input type="button" name="reup" value="수정">
												<input type="hidden" name="rno" value="${list.rno }">
												<input type="hidden" name="rcontent" value="${list.rcontent }">
												<input type="button" name="redel" value="삭제">
												<input type="hidden" name="rno" value="${list.rno }">
											</td>
								</c:if>
						</c:otherwise>
					</c:choose>
				</tr>
				</c:forEach>
				<tr>
					<td>${sessionScope.mvo.id }</td>
					<td colspan="4"><textarea rows="2" cols="45" id="replyContent" style="resize:none"></textarea></td>
					<td><input type="button" id="insertRe" value="댓글"></td>
				</tr>
			</table>
		</c:if>
</c:if>

<!-- 댓글 수정 (다이얼로그) -->
<div id="editReplyDialog" title="코멘트 수정"></div>

<!-- 댓글 댓글 (다이얼로그) -->
<div id="reReplyDialog" title="답 코멘트"></div>
</center>
</body>
</html>